import Api from '@core/http/decorates/api';
import { AxiosInstance } from 'axios';
import { GetUserInfoData } from './models/GetUserInfoData';

@Api({ prefix: 'user' })
export class User {
  private readonly http: AxiosInstance;

  /**
   * 获得用户信息
   *
   * @param {string} userId
   * @return {*}
   * @memberof User
   */
  async getUserInfo(userId?: string) {
    return (
      await this.http.get<GetUserInfoData>('getUserInfo', {
        params: {
          userId,
        },
      })
    ).data;
  }

  /**
   * 更换头像
   *
   * @param {string} userId
   * @param {string} avatar
   * @return {*}
   * @memberof User
   */
  async changeAvatar(userId: string, avatar: string) {
    return (
      await this.http.post<string>('changeAvatar', {
        userId,
        avatar,
      })
    ).data;
  }
}
